#include "ani.h"
#include <QtGui/QApplication>
#include <QtGui>

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	ani b;
	


	QStateMachine machine;
	QState *s1 = new QState;
	QState *s2 = new QState;
	QState *s3 = new QState;

	QWidget w;
	b.SetTmp(&w);
	QVBoxLayout *vbl = new QVBoxLayout;
	
	QPushButton *btn1 = new QPushButton;
	btn1->setText("1 --> 2");
	vbl->addWidget(btn1);

	QPushButton *btn2 = new QPushButton;
	btn2->setText("2 --> 3");
	vbl->addWidget(btn2);
	
	QPushButton *btn3 = new QPushButton;
	btn3->setText("3 --> 1");
	vbl->addWidget(btn3);

	QLabel * lab = new QLabel;
	lab->setText("what");
	vbl->addWidget(lab);

	QPushButton *btn = new QPushButton;
	btn->setText("Doit");
	vbl->addWidget(btn);

	QObject::connect(btn,SIGNAL(clicked()),&b,SLOT(Doit()));

	//w.setMinimumSize(QSize(250,250));
	w.setLayout(vbl);
	w.show();


	//s1->addTransition(btn,SIGNAL(clicked()),s2);
	QSignalTransition *transition = s1->addTransition(btn1, SIGNAL(clicked()), s2);
	QPropertyAnimation * pa1 = new QPropertyAnimation(&w, "geometry");
	pa1->setDuration(2000);
	//pa1->setStartValue(QRectF(100,100,500,500));
	//pa1->setEndValue(QRectF(100,100,200,200));

	transition->addAnimation(pa1);

	//s2->addTransition(btn,SIGNAL(clicked()),s1);
	QSignalTransition *transition2 = s2->addTransition(btn2, SIGNAL(clicked()), s3);
	QPropertyAnimation * pa2 = new QPropertyAnimation(&w, "geometry");
	pa2->setDuration(3000);
	//pa2->setStartValue(QRectF(100,100,200,200));
	//pa2->setEndValue(QRectF(100,100,500,500));

	transition2->addAnimation(pa2);

	QSignalTransition *transition3 = s3->addTransition(btn3, SIGNAL(clicked()), s1);
	QPropertyAnimation * pa3 = new QPropertyAnimation(&w, "geometry");
	pa3->setDuration(4000);
	//pa3->setStartValue(QRectF(100,100,500,500));
	//pa3->setEndValue(QRectF(100,100,200,200));
	transition3->addAnimation(pa3);


	s1->assignProperty(lab, "text", "In state s1");
	s2->assignProperty(lab, "text", "In state s2");
	s3->assignProperty(lab, "text", "In state s3");
	
	s1->assignProperty(&w, "geometry", QRectF(100, 100, 200, 200));
	s2->assignProperty(&w, "geometry", QRectF(100, 100, 400, 400));
	s3->assignProperty(&w, "geometry", QRectF(100, 100, 600, 600));

	machine.addState(s1);
	machine.addState(s2);	
	machine.addState(s3);
	machine.setInitialState(s1);
	machine.start();

	return a.exec();
}
